classdef LambaIdentificationGA < LambaIdentification
    properties 
    end
    methods
        
        %% we need to look for better way to identify Lamba
        %% Search for that 
        function Lamba = IdentifyLamba(obj, Rk, Indx,Grad, eigVals,eigVects, Dims)
            syms y;           
            Step = zeros(size(Grad));
            for i = 1: Dims                
                Grad_ = eigVects(:,i) * Grad';
                if i == Indx
                    Grad_ = Grad_/(eigVals(i)- y ) ;
                else
                    Grad_ = Grad_/(eigVals(i)+ y);
                end
                Step = Step - Grad_' * eigVects(:,i);
            end
            FinalFunc = 0;
            for i = 1: Dims                
                FinalFunc = FinalFunc + Step(i)^2;
            end
            FinalFunc = FinalFunc - Rk; %^2;
            %FinalFunc = diff(FinalFunc,'y');
            lamba = solve (FinalFunc,y);
            l = size(lamba);
            Lamba = [];
            for i= 1: l(1)               
                 y = double(lamba(i));
                 Lamba = [Lamba; y];
            end
            
        end        
        
        function Lamba = IdentifyLamba1(obj, Rk,Grad, eigVals,eigVects, Dims)
            syms y;           
            Step = zeros(size(Grad));
            for i = 1: Dims                
                Grad_ = eigVects(:,i) * Grad';
                Grad_ = Grad_/(eigVals(i)- y ) ;                
                Step = Step - Grad_' * eigVects(:,i);
            end
            FinalFunc = 0;
            for i = 1: Dims                
                FinalFunc = FinalFunc + Step(i)^2;
            end
            FinalFunc = FinalFunc - Rk; %^2;
            %FinalFunc = diff(FinalFunc,'y');
            lamba = solve (FinalFunc,y);
            l = size(lamba);
            Lamba = [];
            for i= 1: l(1)               
                 y = double(lamba(i));
                 Lamba = [Lamba; y];
            end
            
        end        
    end
end
